function [WA,WAD]=interpolate(XX,YY,ZZ,XA,YA)
fitresult=scatteredInterpolant(XX,YY,ZZ,'natural');
WA=zeros(0); WAD=zeros(0);
WADX=zeros(0); WADY=zeros(0);
for i=1:length(XA)
    WA(i)=fitresult(XA(i),YA(i));
    if isnan(WA(i))
        disp('Bad interpolate.')
        pause
    end
    d=0.005;
    while true
        if abs(fitresult(XA(i)+d,YA(i))-fitresult(XA(i)-d,YA(i)))<0.0001
            WADX(i)=(fitresult(XA(i)+d,YA(i))-fitresult(XA(i),YA(i)))/d;
            break
        else
            d=d*0.5;
        end
        if d==0
            if ~isnan(fitresult(XA(i)+0.01,YA(i)))
                WADX(i)=(fitresult(XA(i)+0.01,YA(i))-fitresult(XA(i),YA(i)))/0.01;
                break
            elseif ~isnan(fitresult(XA(i)-0.01,YA(i)))
                WADX(i)=(fitresult(XA(i),YA(i))-fitresult(XA(i)-0.01,YA(i)))/0.01;
                break
            else
                disp('Bad interpolate.')
                pause
            end
        end
    end
    while true
        if abs(fitresult(XA(i),YA(i)+d)-fitresult(XA(i),YA(i)-d))<0.0001
            WADY(i)=(fitresult(XA(i),YA(i)+d)-fitresult(XA(i),YA(i)))/d;
            break
        else
            d=d*0.5;
        end
        if d==0
            if ~isnan(fitresult(XA(i),YA(i)+0.01))
                WADY(i)=(fitresult(XA(i),YA(i)+0.01)-fitresult(XA(i),YA(i)))/0.01;
                break
            elseif ~isnan(fitresult(XA(i),YA(i)-0.01))
                WADY(i)=(fitresult(XA(i),YA(i))-fitresult(XA(i),YA(i)-0.01))/0.01;
                break
            else
                disp('Bad interpolate.')
                pause
            end
        end
    end
    WAD(i)=WADX(i)/(WADY(i)^2+1)^0.5;
end
end